package com.css.fxfzaqbz.modules.assess1.controller;


import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.assess1.entity.DestoryRateEntity;
import com.css.fxfzaqbz.modules.assess1.queryParams.DestoryRateQueryParams;
import com.css.fxfzaqbz.modules.assess1.service.DestoryRateService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @author y1fan
 * @create 2022-11-28 15:23
 * 房屋破坏比率 接口
 */
@RestController
@RequestMapping("/fxfzaqbz/DestoryRate")
@Slf4j
public class DestoryRateController {

    @Resource
    DestoryRateService destoryRateService ;

    /**
     * 查询
     * @param queryParams
     * @return
     */
    @GetMapping("/getPage")
        public RestResponse getPage(DestoryRateQueryParams queryParams){
            RestResponse restResponse = null;
            try{
                List<DestoryRateEntity> page=destoryRateService.getPage(queryParams);
                restResponse = RestResponse.succeed(page);
            }catch (Exception e){
                String errormessage="查询失败";
                log.error(errormessage,e);
                restResponse= RestResponse.fail(errormessage);
            }
        return restResponse;
    }

    /**
     * 修改
     * @param list
     * @return
     */
    @PostMapping("/update")
    public RestResponse update(@RequestBody List<DestoryRateEntity> list){
        RestResponse restResponse = null;
        try{
            destoryRateService.update(list);
            restResponse = RestResponse.succeed("修改成功");
        }catch (Exception e){
            String errormessage="修改失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    @GetMapping("/query")
    public RestResponse query(DestoryRateQueryParams queryParams){
        RestResponse restResponse = null;
        try{
            List<DestoryRateEntity> page=destoryRateService.query(queryParams);
            restResponse = RestResponse.succeed(page);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 保存
     * @param list
     * @return
     */
    @PostMapping("/save")
    public RestResponse save(@RequestBody List<DestoryRateEntity> list){
        RestResponse restResponse = null;
        try{
            destoryRateService.save(list);
            restResponse = RestResponse.succeed("修改成功");
        }catch (Exception e){
            String errormessage = e.getMessage();
            if(StringUtils.isBlank(errormessage)) {
                errormessage = "修改失败";
            }
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 导出
     * @param response
     */
    @PostMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response, DestoryRateQueryParams queryParams){
        RestResponse restResponse = null;
        try {
            destoryRateService.exportExcel(response,queryParams);
            restResponse = RestResponse.succeed("导出成功");
        } catch (Exception e) {
            String errormessage = e.getMessage();
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        ///return restResponse;
    }



    /**
     * 导入
     * @param
     */
    @PostMapping("/importExcel")
    public RestResponse importExcel(MultipartFile file,DestoryRateEntity destoryRateEntity){
        RestResponse restResponse = null;
        try {
            String s = destoryRateService.importExcel(file, destoryRateEntity);
            restResponse = RestResponse.succeed(s);

        } catch (Exception e) {
            String errormessage = e.getMessage();
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 获取当前登陆人所在省市，以及判断当前登陆人属于国家级和省级管理员
     * @param
     * @return
     */
    @GetMapping("/getLoginPersonInfo")
    public RestResponse getLoginPersonInfo(){
        RestResponse restResponse = null;
        try{
            Map<String,Object> map=destoryRateService.getLoginPersonInfo();
            restResponse = RestResponse.succeed(map);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }





}
